package cn.sfrog.project.biz.web.controller;

import cn.sfrog.common.core.controller.BaseController;
import cn.sfrog.common.core.domain.ApiAjaxResult;
import cn.sfrog.common.core.page.TableDataInfo;
import cn.sfrog.common.utils.SecurityUtils;
import cn.sfrog.project.biz.admin.mapper.BizStudyProjectSponsorMapper;
import cn.sfrog.project.biz.admin.service.IBizStudyProjectService;
import cn.sfrog.project.biz.web.vo.study.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;


@Slf4j
@RestController
@RequestMapping("/api/studyProject")
@Api(value = "/api/studyProject", tags = "APP学研项目相关")
public class AppStudyProjectController extends BaseController {

    @Autowired
    private IBizStudyProjectService bizStudyProjectService;
    @Resource
    private BizStudyProjectSponsorMapper bizStudyProjectSponsorMapper;

    @ApiOperation(value = "获取学研项目列表")
    @GetMapping("/getStudyProjectList")
    public TableDataInfo<List<AppStudyProjectResultVO>> getStudyProjectList(AppStudyProjectQueryVO queryVO){
        startPage();
        List<AppStudyProjectResultVO> studyProjectResultVOList = bizStudyProjectService.selectAppStudyProjectList(queryVO);
        return getDataTable(studyProjectResultVOList);
    }

    @ApiOperation(value = "获取学研项目详情")
    @GetMapping("/getStudyProjectDetail/{id}")
    public ApiAjaxResult<AppStudyProjectDetailResultVO> getStudyProjectDetail(@PathVariable("id") Long id){
       AppStudyProjectDetailResultVO resultVO =  bizStudyProjectService.selectAppStudyProjectDetail(id);
       return ApiAjaxResult.success(resultVO);
    }

    @ApiOperation(value = "项目捐助")
    @PostMapping("/projectDonate")
    public ApiAjaxResult projectDonate(@RequestBody @Validated AppProjectDonateFormVO formVO){
        return ApiAjaxResult.success(bizStudyProjectService.projectDonate(formVO));
    }

    @ApiOperation(value = "获取医生参加的学研项目列表")
    @GetMapping("/getDoctorStudyProjectList")
    public TableDataInfo<AppStudyProjectResultVO> getDoctorStudyProjectList(AppStudyProjectQueryVO queryVO){
        queryVO.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        startPage();
        List<AppStudyProjectResultVO> studyProjectResultVOList = bizStudyProjectService.selectDoctorStudyProjectList(queryVO);
        return getDataTable(studyProjectResultVOList);
    }

    @ApiOperation(value = "获取研项目赞助明细列表")
    @GetMapping("/getStudyProjectSponsorList/{projectId}")
    public TableDataInfo<AppStudyProjectSponsorVO> getStudyProjectSponsorList(@PathVariable("projectId") Long projectId){
        startPage();
        //项目捐赠记录
        List<AppStudyProjectSponsorVO> sponsorList =  bizStudyProjectSponsorMapper.selectAppProjectSponsorList(projectId);
       return getDataTable(sponsorList);
    }

}
